function abort(){
    param($msg)
    Write-Output "Error: $msg ... aborting"
    exit 1
}
$configDir="$env:USERPROFILE\.vlassist"
$configFile="${configDir}\config.json"
$helpFile="${PSScriptRoot}\help.html"

if (!(test-path $configFile))
{
    New-Item -Path "$env:USERPROFILE" -Name ".vlassist" -ItemType "directory"
    Copy-Item "${PSScriptRoot}\config.json.template" "${configFile}" -Force
}

$collections = (get-content ${configFile} | convertfrom-json).Collections

set-content $helpFile '<script src="md.js"></script><noscript>'
add-content $helpFile "# Assist Help"
add-content $helpFile ""

add-content $helpFile "| Name | Type | Hotkey | Path | Comment |"
add-content $helpFile "| -- | -- | -- | -- | -- |"

foreach($item in $collections)
{
    $name = $item.Name
    $key = $item.Key
    $type = $item.Type
    $path = $item.Path

    if ($null -ne $key){
        $key = $key.replace('+',"Shift+").replace("!","Alt+").replace("#","Win+").replace('^',"Ctrl+")
    }

    add-content $helpFile "| $name | $type | $key | ${path} |  |"
}

Write-Output "generate help task has been done"
